<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="chart-container">
        <canvas id="myChart" width="400" height="200"></canvas>
    </div>
    <script>

        const chartContainer = document.querySelector('.chart-container');
        const ro = new ResizeObserver((entries) => { // 创建ResizeObserver实例，监听图表容器尺寸变化
            entries.forEach((e) => console.log('尺寸变化', e.contentRect));
        });
        // 监听图表容器尺寸变化
        ro.observe(chartContainer);
    </script>
</body>
</html>
